package com.leyou.auth.filter;

import com.leyou.auth.config.JwtProperties;
import com.leyou.auth.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class MyLogoutHandler implements LogoutSuccessHandler {



	private AuthService authService;


    public MyLogoutHandler(AuthService authService) {
       this.authService = authService;
    }


    /*@Override
    public void logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) {
        authService.logout(httpServletRequest,httpServletResponse);
    }*/

    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        //刷新token就是添加一个JwtVerifyFilter 然后和这里类似调用token的刷新方法就行
        authService.logout(httpServletRequest,httpServletResponse);
    }
}
